var t = require("../../../../@babel/runtime/helpers/objectSpread2"), a = getApp();

Page({
    data: {
        fileList: [],
        name: "",
        logo: "",
        type: "",
        id: "",
        share: "",
        merchant_member_id: ""
    },
    onLoad: function(t) {
        t.share && this.setData({
            share: t.share
        }), t.merchant_member_id && this.setData({
            merchant_member_id: t.merchant_member_id
        }), this.setData({
            type: t.type
        }), "edit" == t.type && (this.setData({
            id: t.id
        }), this.detail());
    },
    detail: function() {
        var t = this;
        a._postNetWork({
            url: a.getNetAddresss("plugin.lawyer-platform.frontend.controllers.business.getDetail"),
            data: {
                id: this.data.id
            },
            success: function(e) {
                1 == e.data.result ? (t.data.fileList.push({
                    url: e.data.data.detail.logo_img_image,
                    status: "done"
                }), t.setData({
                    name: e.data.data.detail.name,
                    logo: e.data.data.detail.logo_img_image,
                    fileList: t.data.fileList
                })) : a.tips(e.data.msg);
            }
        });
    },
    onReady: function() {},
    delete: function() {
        this.setData({
            fileList: []
        });
    },
    handle: function() {
        if ("" == this.data.name) return a.tips("请输入企业名称");
        if ("" == this.data.logo) return a.tips("请上传logo");
        var t = "", e = {
            form: {
                name: this.data.name,
                logo: this.data.logo
            }
        };
        "add" == this.data.type ? (t = a.getNetAddresss("plugin.lawyer-platform.frontend.controllers.business.create"), 
        "enterprise" == this.data.share && (e.form.merchant_member_id = this.data.merchant_member_id)) : (e.id = this.data.id, 
        t = a.getNetAddresss("plugin.lawyer-platform.frontend.controllers.business.edit")), 
        a._postNetWork({
            url: t,
            data: e,
            success: function(t) {
                1 == t.data.result ? (a.tips(t.data.msg), wx.navigateBack()) : a.tips(t.data.msg);
            }
        });
    },
    afterRead: function(e) {
        var i = this;
        wx.showLoading({
            title: "上传中"
        });
        var s = e.detail.file, n = a.getNetAddresss("upload.uploadPic");
        wx.uploadFile({
            url: n,
            filePath: s.url,
            name: "file",
            success: function(e) {
                a.tips("上传成功");
                var n = JSON.parse(e.data), d = i.data.fileList, o = void 0 === d ? [] : d;
                o.push(t(t({}, s), {}, {
                    url: n.data.img_url,
                    status: "done",
                    message: "上传完成"
                })), i.setData({
                    fileList: o,
                    logo: n.data.img_url
                });
            },
            fail: function(e) {
                a.tips("上传成功");
                var i = [];
                i.push(t(t({}, s), {}, {
                    url: "",
                    status: "failed",
                    message: "上传失败"
                })), this.setData({
                    fileList: i
                });
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});